use Dosvid
go

if exists(select 1
		  from sysobjects
		  where name = 'Candidat_RangeTerritories')
  drop table Candidat_RangeTerritories
go

create table Candidat_RangeTerritories
(
  Id int identity(1,1) not null,
  CandidateId int not null,
  RangeTerritoryId int not null
)  
go

alter table Candidat_RangeTerritories add constraint PK_Candidat_Territories_ID primary key(Id)
go

create nonclustered index IX_Candidat_RangeTerritories_CandidateId on Candidat_RangeTerritories
       (CandidateId asc)
go

alter table Candidat_RangeTerritories add constraint FK_Candidat_RangeTerritories_TeretoryId 
      foreign key (RangeTerritoryId) references Territories(Id) 
go

alter table Candidat_RangeTerritories add constraint FK_Candidat_RangeTerritories_CandidateId 
      foreign key (CandidateId) references Candidates(Id) 
go

